package com.app.service.impl;

import com.app.service.QiniuService;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;

import com.qiniu.storage.BucketManager;
import com.qiniu.storage.UploadManager;
import com.qiniu.util.Auth;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;


/**
 * @author litblue
 * @version 1.0.0
 * @time 2020/11/19  23:47
 */
@Slf4j
@Service
public class QiniuServiceImpl implements QiniuService {
    @Autowired
    private UploadManager uploadManager;
    @Autowired
    private BucketManager bucketManager;
    @Autowired
    private Auth auth;
    @Value("${qiniu.bucket}")
    private String bucket;


    @Override
    public String uploadFile(MultipartFile file) throws Exception {  //上传文件
        String token = auth.uploadToken(bucket);  //获取token
        String key = IdWorker.getIdStr();
        uploadManager.put(file.getBytes(), key, token);//图片上传
        String url = "http://dsvip1.vip/" + key;
        return url;
    }

    @Override
    public String delete(String name) {
        return null;
    }


}
